package com.itheima.CSM_preX.aaaController;

import com.itheima.CSM_preX.aabService.Serv.MemberServ;
import com.itheima.common.entity.Result;
import com.itheima.pojo.DTO.DTOmLOGIN;
import com.itheima.pojo.Entity.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/member")
public class MemberController {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private MemberServ memberServ;

    @PostMapping("/login")
    public Result login(@RequestBody DTOmLOGIN kk) {
        String code = (String) redisTemplate.opsForValue().get(kk.getTelephone());
        if (code.equals(kk.getValidateCode())) {
            Member member = memberServ.getByPhoneNumber(kk.getTelephone());
            if (member == null) {
                Member mm = new Member();
                mm.setPhoneNumber(kk.getTelephone());
                memberServ.add(mm);
            }
            return new Result(true, "验证码正确");
        }
        //todo 判断会员？

        return new Result(true, "验证码输入错误");


    }
}
